package com.power.algorithm;

/**
 * @description:
 * @author: jiangnan
 * @time: 2021/6/16 3:22 下午
 */
public class Solution122 {
    public int maxProfit(int[] prices) {
        int total = 0;
        int j = 1;
        int[] newTotal = new int[prices.length - 1];

        while (j < prices.length) {
            if (prices[j] - prices[j - 1] >= 0) {
                total += (prices[j] - prices[j - 1]);
            }
            j++;

        }

        return total;
    }

    public int maxProfit2(int[] prices) {
        int ans = 0;
        for (int i = 0; i < prices.length - 1; i++) {
            ans += Math.max(0, prices[i + 1] - prices[i]);
        }
        return ans;
    }

    public static void main(String[] args) {
        int[] prices = {7, 1, 5, 3, 6, 4};
        Solution122 solution122 = new Solution122();
        System.out.println(solution122.maxProfit2(prices));
    }
}
